package com.jws.battleship;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;

public class HomeMenuBackground extends View
{ 
	private int mScreenWidth;
	private int mScreenHeight;
	private RectF mSpace;
	private RectF mSpaceStroke;
	private Paint mPaint;
	private Paint mPaintStroke;
	private Rect mRect; 
	private LinearGradient mGradient;
	private final int mHeighMenu;
	private float scale;
	private int menu_contract_height;
	
    public HomeMenuBackground(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        
        mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
        mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
        
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mSpace = new RectF(-20, 2, mScreenWidth + 20, 148);
        mSpaceStroke = new RectF(-22, 0, mScreenWidth + 22, 150);
        mRect = new Rect();
        
        mPaintStroke = new Paint();
        mPaintStroke.setStyle(Paint.Style.STROKE);
        mPaintStroke.setStrokeCap(Paint.Cap.ROUND);
        mPaintStroke.setStrokeWidth(2);
        mPaintStroke.setColor(Color.BLACK);
        mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
        
        scale = getContext().getResources().getDisplayMetrics().density;
    	menu_contract_height = (int)(getResources().getInteger(R.integer.menu_adv_contract_height) * scale);
    	mHeighMenu = (int) (mScreenHeight*0.8);
    }

    @Override
    public void onDraw(Canvas canvas)
    {		
    	mRect.set(0, 75, canvas.getWidth(), canvas.getHeight());
    	canvas.drawArc(mSpaceStroke, 180, 360, true, mPaintStroke);
    	canvas.drawArc(mSpace, 180, 360, true, mPaint);
        canvas.drawRect(mRect, mPaint);
    }
    
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    {
    	if(mGradient == null)
    	{
    		mGradient = new LinearGradient(0, 0, 0, MeasureSpec.getSize(heightMeasureSpec), Color.WHITE, Color.GRAY, Shader.TileMode.MIRROR);
    		mPaint.setShader(mGradient);
    	}
    	
    	setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);		
    	super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    
    public void makeBig()
    {
    	RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, mHeighMenu );
    	rl.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    	this.setLayoutParams(rl);
    }
    
    public void makeSmall()
    {    	
    	RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, menu_contract_height );
    	rl.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    	this.setLayoutParams(rl);
    }
}
